/-boot ...
BootController.ts
BootLayout.ts
StorageLoader.ts
boot.ts
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-storage
/-storage/attached
/-storage/attached/api
/-storage/attached/dom
DetectStorage.ts
LoadStorage.ts
UpdateStorage.ts
/-storage/attached/indexedDB
/-storage/attached/localStorage
/-storage/attached/webSQL
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
x
      var loadingFromPersistence = this._persistence && this._persistence.editedUTC > this._domStorage.editedUTC;
12
    private _persistence: storage.attached.LoadStorage = null;
13
14
    constructor(
15
      private _dom: Dom,
16
      private _storageElement: HTMLElement,
17
      private _uniqueKey: string) {
18
    }
19
20
    loadStorage(callbacks: StorageLoader.Callbacks) {
21
      if (this._callbacks)
22
        throw new Error('Cannot load storage twice.');
23
24
      this._callbacks = callbacks;
25
26
      try {
27
        this._domStorage =
28
        new storage.attached.dom.DetectStorage(this._storageElement, this._dom.documenOverride).
29
          detectStorageSync();
30
      }
31
      catch (err) {
32
        this._callbacks.detectionComplete(err, null, null, null);
33
        return;
34
      }
35
36
      var detectIndexedDB = new storage.attached.indexedDB.DetectStorage();
37
      var detectWebSQL = new storage.attached.webSQL.DetectStorage();
38
39
      detectIndexedDB.detectStorageAsync(this._uniqueKey, (error, load) => {
40
        this._indexedDBDetectCompleted = true;
41
42
        if (error) {
43
          if (!this._webSqlDetectCompleted)
44
            return; // wait for webSQL, it can still succeed
45
46
          // revert to webSQL results
47
          this._detectCompleted();
48
        }
49
        else {
50
          this._persistence = load;
51
          this._persistenceName = 'indexedDB';
52
53
          this._detectCompleted();
54
        }
55
      });
56
57
      detectWebSQL.detectStorageAsync(this._uniqueKey, (error, load) => {
58
        this._webSqlDetectCompleted = true;
59
60
        if (this._persistence)
61
          return;
62
63
        this._persistence = load;
64
        if (this._indexedDBDetectCompleted)
65
          this._detectCompleted();
66
      });
67
    }
68
69
    private _detectCompleted() {
70
      var loadingFromPersistence = this._persistence && this._persistence.editedUTC > this._domStorage.editedUTC;
71
72
      var sourceLoad = loadingFromPersistence ? this._persistence : this._domStorage;
73
      var targetLoad = loadingFromPersistence ? this._domStorage : this._persistence;
74
75
      console.log('loadingFromPersistence: ' + loadingFromPersistence, sourceLoad, targetLoad);
96:0